// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-16 20:22
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.ArraysTrain;

public class MissingNumber {
    /**
     * 寻找数组中的缺失数据
     */
    public int missingNumber(int[] nums) {
        /*
            因为数据是连续的，只能中断一个元素，所以可以通过总和判断缺失的数字
         */
        int m = nums.length, sum = 0, all = m;
        for (int i = 0; i < m; i++) {
            sum += nums[i];
            all += i;
        }
        return all - sum;
    }
}
